package com.ruoyi.system.domain;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 股票数据对象 stock
 * 
 * @author ruoyi
 * @date 2021-12-27
 */
public class Stock extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 编号 */
    private Long id;

    /** 交易时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "交易时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date date;

    /** 代码 */
    @Excel(name = "代码")
    private String symbol;

    /** 名称 */
    @Excel(name = "名称")
    private String name;

    /** 最新价 */
    @Excel(name = "最新价")
    private BigDecimal trade;

    /** 涨跌额 */
    @Excel(name = "涨跌额")
    private BigDecimal pricechange;

    /** 涨跌幅 */
    @Excel(name = "涨跌幅")
    private BigDecimal changepercent;

    /** 买入 */
    @Excel(name = "买入")
    private BigDecimal buy;

    /** 卖出 */
    @Excel(name = "卖出")
    private BigDecimal sell;

    /** 昨收 */
    @Excel(name = "昨收")
    private BigDecimal settlement;

    /** 今开 */
    @Excel(name = "今开")
    private BigDecimal open;

    /** 最高 */
    @Excel(name = "最高")
    private BigDecimal high;

    /** 最低 */
    @Excel(name = "最低")
    private BigDecimal low;

    /** 成交量 */
    @Excel(name = "成交量")
    private Long volume;

    /** 成交额 */
    @Excel(name = "成交额")
    private Long amount;

    /** 流动股本(股) */
    @Excel(name = "流动股本(股)")
    private Long share;

    /** 换手率=成交量(股)/流动股本(股) */
    @Excel(name = "换手率=成交量(股)/流动股本(股)")
    private BigDecimal turnover;


    /** 开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "交易时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date startTime;

    /** 结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "交易时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date endTime;

    public void setId(Long id) 
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }
    public void setDate(Date date) 
    {
        this.date = date;
    }

    public Date getDate() 
    {
        return date;
    }
    public void setSymbol(String symbol) 
    {
        this.symbol = symbol;
    }

    public String getSymbol() 
    {
        return symbol;
    }
    public void setName(String name) 
    {
        this.name = name;
    }

    public String getName() 
    {
        return name;
    }
    public void setTrade(BigDecimal trade) 
    {
        this.trade = trade;
    }

    public BigDecimal getTrade() 
    {
        return trade;
    }
    public void setPricechange(BigDecimal pricechange) 
    {
        this.pricechange = pricechange;
    }

    public BigDecimal getPricechange() 
    {
        return pricechange;
    }
    public void setChangepercent(BigDecimal changepercent) 
    {
        this.changepercent = changepercent;
    }

    public BigDecimal getChangepercent() 
    {
        return changepercent;
    }
    public void setBuy(BigDecimal buy) 
    {
        this.buy = buy;
    }

    public BigDecimal getBuy() 
    {
        return buy;
    }
    public void setSell(BigDecimal sell) 
    {
        this.sell = sell;
    }

    public BigDecimal getSell() 
    {
        return sell;
    }
    public void setSettlement(BigDecimal settlement) 
    {
        this.settlement = settlement;
    }

    public BigDecimal getSettlement() 
    {
        return settlement;
    }
    public void setOpen(BigDecimal open) 
    {
        this.open = open;
    }

    public BigDecimal getOpen() 
    {
        return open;
    }
    public void setHigh(BigDecimal high) 
    {
        this.high = high;
    }

    public BigDecimal getHigh() 
    {
        return high;
    }
    public void setLow(BigDecimal low) 
    {
        this.low = low;
    }

    public BigDecimal getLow() 
    {
        return low;
    }
    public void setVolume(Long volume) 
    {
        this.volume = volume;
    }

    public Long getVolume() 
    {
        return volume;
    }
    public void setAmount(Long amount) 
    {
        this.amount = amount;
    }

    public Long getAmount() 
    {
        return amount;
    }
    public void setShare(Long share) 
    {
        this.share = share;
    }

    public Long getShare() 
    {
        return share;
    }
    public void setTurnover(BigDecimal turnover) 
    {
        this.turnover = turnover;
    }

    public BigDecimal getTurnover() 
    {
        return turnover;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("date", getDate())
            .append("symbol", getSymbol())
            .append("name", getName())
            .append("trade", getTrade())
            .append("pricechange", getPricechange())
            .append("changepercent", getChangepercent())
            .append("buy", getBuy())
            .append("sell", getSell())
            .append("settlement", getSettlement())
            .append("open", getOpen())
            .append("high", getHigh())
            .append("low", getLow())
            .append("volume", getVolume())
            .append("amount", getAmount())
            .append("share", getShare())
            .append("turnover", getTurnover())
            .toString();
    }

    public Stock() {

    }

    public Stock(String symbol) {
        this.symbol = symbol;
    }

    public Stock(String symbol, String name, String trade, String pricechange, String changepercent, String buy, String sell, String settlement, String open, String high, String low, String volume, String amount) {
        this.symbol = symbol;
        this.name = name;
        try {
        this.trade = Optional.ofNullable(trade).filter(s->!s.equals("--")).map(s->new BigDecimal(trade)).orElse(new BigDecimal(-1));

        }catch (Exception e){
//            e.printStackTrace();
        }
        this.pricechange = Optional.ofNullable(pricechange).filter(s->!s.equals("--")).map(s->new BigDecimal(pricechange)).orElse(new BigDecimal(-1));
        this.changepercent = Optional.ofNullable(changepercent).filter(s->!s.equals("--")).map(s->new BigDecimal(changepercent)).orElse(new BigDecimal(-1));
        this.buy = Optional.ofNullable(buy).filter(s->!s.equals("--")).map(s->new BigDecimal(buy)).orElse(new BigDecimal(-1));
        this.sell = Optional.ofNullable(sell).filter(s->!s.equals("--")).map(s->new BigDecimal(sell)).orElse(new BigDecimal(-1));
        this.settlement = Optional.ofNullable(settlement).filter(s->!s.equals("--")).map(s->new BigDecimal(settlement)).orElse(new BigDecimal(-1));
        this.open = Optional.ofNullable(open).filter(s->!s.equals("--")).map(s->new BigDecimal(open)).orElse(new BigDecimal(-1));
        this.high = Optional.ofNullable(high).filter(s->!s.equals("--")).map(s->new BigDecimal(high)).orElse(new BigDecimal(-1));
        this.low = Optional.ofNullable(low).filter(s->!s.equals("--")).map(s->new BigDecimal(low)).orElse(new BigDecimal(-1));
        this.volume = Optional.ofNullable(volume).filter(s->!s.equals("--")).map(s->new BigDecimal(volume).longValue()).orElse(-1l);
        this.amount = Optional.ofNullable(amount).filter(s->!s.equals("--")).map(s->new BigDecimal(amount).longValue()).orElse(-1l);
    }

    public Stock(Date date, String symbol, String name, String trade, String open, String high, String low, String volume,String share,String turnover) {

        this.date = date;
        this.symbol = symbol;
        this.name = name;
        this.trade = Optional.ofNullable(trade).map(s->new BigDecimal(trade)).orElse(new BigDecimal(-1));
        this.open = Optional.ofNullable(open).map(s->new BigDecimal(open)).orElse(new BigDecimal(-1));
        this.high = Optional.ofNullable(high).map(s->new BigDecimal(high)).orElse(new BigDecimal(-1));
        this.low = Optional.ofNullable(low).map(s->new BigDecimal(low)).orElse(new BigDecimal(-1));
        this.volume = Optional.ofNullable(volume).map(s->new BigDecimal(volume).longValue()).orElse(-1l);
        this.share = Optional.ofNullable(share).map(s->new BigDecimal(share).longValue()).orElse(-1l);

    }
}
